<?php
include('content_pages_controller.php');

class PostsController extends AppController
{
    var $name = 'Posts';

    function index() { 
        $posts = $this->Post->findAll(); 
        if(isset($this->params['requested'])) { 
             return $posts; 
        } 
        $this->set('posts', $posts); 
    }

    function view($id)
    {
        $this->Post->id = $id;
        $this->set('post', $this->Post->read());
		



    }

    function add()
    {
        if (!empty($this->data))
        {
            if ($this->Post->save($this->data))
            {
                $this->flash('Your post has been saved.','/posts');
            }
        }
    }
	
	function delete($id)
	{
		$this->Post->del($id);
		$this->flash('The post with id: '.$id.' has been deleted.', '/posts');
	}
		
	function edit($id = null)
	{
		if (empty($this->data))
		{
			$this->Post->id = $id;
			$this->data = $this->Post->read();
		}
		else
		{
			if ($this->Post->save($this->data['Post']))
			{
				$this->flash('Your post has been updated.','/posts');
			}
		}
	}	
	
}

?>